package com.luo.controller;


import java.util.List;

import javax.annotation.Resource;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.luo.domain.User;
import com.luo.service.SearchService;

@Controller
@RequestMapping("/search")
public class SearchController {
    //我们先进行一个无数据交互的跳转 直接跳转到 search 页面
    
        //注入SearchService 
    @Resource
    private SearchService searchService;
    
    @RequestMapping("/toSearch")
    public String toSearch(){
      
        return "search";
    }
    
    @RequestMapping("/toTest")
    public String toTest(){
      
        return "test";
    }
    
    
    @RequestMapping("/toAjax")
    public String toAjax(){
      
        return "ajax";
    }
    
    /**
     * 编写与数据进行交互的方法
     */
    
    @RequestMapping("/serchUserByName")
    public String serchUserByName(@RequestParam(value="userName")String userName,Model model){
        //Controller层调用Service层
         //通过用户名查询用户 可能会有多个用户 所以我们用List集合来接收
       List<User> userList =   searchService.serchUserByName(userName);
        
       model.addAttribute("userList",userList);
        return "search";
    }
    
    
    
    
    
    
}
